package com.google.code.expr.lang;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;

/**
 * This class is not really used.  it is the response
 * of the EXPRBlockParser, and contains a list of atoms
 * at the root of a parsed file.  Since the file is
 * normally parsed on the fly, this is not useful.
 * 
 * @author critchie
 *
 */
public class EXPRBlock {

	private ArrayList<EXPRBlockComponent> mContents;
	
	public EXPRBlock() {
		mContents = new ArrayList<EXPRBlockComponent>();
	}
	
	public void add(EXPRBlockComponent pAtom) {
		mContents.add(pAtom);
	}
	
	public ArrayList<EXPRBlockComponent> getComponents() {
		return mContents;
	}

	public String toString() {
		return toString("");
	}
	
	public String toString(String pIndent) {
		StringWriter writer = new StringWriter();
		PrintWriter out = new PrintWriter(writer);
		boolean first = true;
		for (EXPRBlockComponent atom : mContents) {
			if (first) first=false;
			else out.println();
			out.print(atom.toString(pIndent));
		}
		return writer.toString();
	}
}
